package com.ruoyi.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.domain.Volunteers;
import com.ruoyi.service.IVolunteersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * VolunteersController
 * 
 * @author wjy
 * @date 2025-01-11
 */
@RestController
@RequestMapping("/volunteers")
public class VolunteersController extends BaseController
{
    @Autowired
    private IVolunteersService volunteersService;

    /**
     * 查询Volunteers列表
     */
    @RequiresPermissions("volunteers:volunteers:list")
    @GetMapping("/list")
    public TableDataInfo list(Volunteers volunteers)
    {
        startPage();
        List<Volunteers> list = volunteersService.selectVolunteersList(volunteers);
        return getDataTable(list);
    }

    /**
     * 导出Volunteers列表
     */
    @RequiresPermissions("volunteers:volunteers:export")
    @Log(title = "Volunteers", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Volunteers volunteers)
    {
        List<Volunteers> list = volunteersService.selectVolunteersList(volunteers);
        ExcelUtil<Volunteers> util = new ExcelUtil<Volunteers>(Volunteers.class);
        util.exportExcel(response, list, "Volunteers数据");
    }

    /**
     * 获取Volunteers详细信息
     */
    @RequiresPermissions("volunteers:volunteers:query")
    @GetMapping(value = "/{vid}")
    public AjaxResult getInfo(@PathVariable("vid") Long vid)
    {
        return success(volunteersService.selectVolunteersByVid(vid));
    }

    /**
     * 新增Volunteers
     */
    @RequiresPermissions("volunteers:volunteers:add")
    @Log(title = "Volunteers", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Volunteers volunteers)
    {
        return toAjax(volunteersService.insertVolunteers(volunteers));
    }

    /**
     * 修改Volunteers
     */
    @RequiresPermissions("volunteers:volunteers:edit")
    @Log(title = "Volunteers", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Volunteers volunteers)
    {
        return toAjax(volunteersService.updateVolunteers(volunteers));
    }

    /**
     * 删除Volunteers
     */
    @RequiresPermissions("volunteers:volunteers:remove")
    @Log(title = "Volunteers", businessType = BusinessType.DELETE)
	@DeleteMapping("/{vids}")
    public AjaxResult remove(@PathVariable Long[] vids)
    {
        return toAjax(volunteersService.deleteVolunteersByVids(vids));
    }
}
